﻿using RantopadService.Conn;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;

namespace RantopadService.Business
{
    public class FeedBackBusiness
    {
        public static DataTable getAllFeedBack()
        {
            string mysql = "SELECT * FROM rantopad.feedback";
            var dt = MyMySqlHelper.Query(mysql).Tables[0];
            return dt;
        }
        public static DataTable getAllFeedBack(string userid, DateTime st, DateTime et)
        {
            string mysql = "SELECT * FROM rantopad.feedback  where tm>'{0}' and tm<='{1}' ";
            if (userid != "")
            {
                mysql = mysql + "and username='{2}'";
                mysql = string.Format(mysql, st.ToString(), et.ToString(), userid);
            }
            else
            {
                mysql = string.Format(mysql, st.ToString(), et.ToString());
            }


            var dt = MyMySqlHelper.Query(mysql).Tables[0];
            return dt;
        }
        public static int delFeedBack(DataTable dt)
        {
            //string mysql = "delete * from rantopad.feedback  ";
            //return MyMySqlHelper.ExecuteSql(mysql);
            return 0;
        }
        public static int delFeedBack(string id)
        {
            string mysql = "delete  from rantopad.feedback  where idfeedback='{0}'";
            mysql = string.Format(mysql, id);

            return MyMySqlHelper.ExecuteSql(mysql);

        }
        public static int addFeedBack(string username,string title,string type,string content, DateTime tm)
        {

            string mysql = "INSERT INTO `rantopad`.`feedback` (`username`, `title`, `type`, `content`, `tm`) VALUES ('{0}', '{1}', '{2}', '{3}', '{4}')";
            mysql = string.Format(mysql, username,title,type,content, tm);
            return MyMySqlHelper.ExecuteSql(mysql);

        }

        internal static DataTable  getAllFeedBack(string wherelike)
        {
            string mysql = "SELECT * FROM rantopad.feedback where username like '%{0}%' or title like '%{0}%' or tm like '%{0}%'or type like '%{0}%'or content like '%{0}%'";
            mysql = string.Format(mysql, wherelike);
            var dt = MyMySqlHelper.Query(mysql).Tables[0];
            return dt;
        }
    }
}